#include "shmipc/com/xmessage_allocator.h"


namespace shmipc::com {
using namespace shmipc::core;

XResult<XMessageSp> XMessageAllocator::alloc(XMessageType type, MessageId msg_id, uint32_t payload_size, const uint8_t* payload /*= nullptr*/) {
    return alloc(type, msg_id, 0, payload_size, payload);
}

XResult<XMessageSp> XMessageAllocator::alloc(XMessageType type, MessageId msg_id, SequenceNumber seq_num, uint32_t payload_size, const uint8_t* payload /*= nullptr*/) {
    XMessageSp msg = XMessage::CreateMsg(type, msg_id, seq_num, payload_size, payload);
    if (msg) {
        return {msg};
    }

    return XResult<XMessageSp>::FromError(XErrC::InsufficientReousces);
}
} //namespace shmipc::com